package pers.vic.practice.module.statistics.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pers.vic.boot.base.model.BaseResponse;
import pers.vic.practice.module.statistics.model.CharBarModel;
import pers.vic.practice.module.statistics.model.ScoreModel;
import pers.vic.practice.module.statistics.service.StatisticsService;
import pers.vic.practice.module.system.model.SysDict;
import pers.vic.practice.module.system.service.SysDictService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述: 统计
 * @author Vic.xu
 * @date 2022-04-21 11:14
 */
@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    @Resource
    private StatisticsService statisticsService;




    @PostMapping("/classesNum")
    public BaseResponse<?> classesNum(){
        CharBarModel model = new CharBarModel();

        statisticsService.classesNum().forEach(n->{
            model.addLabels(n.getClassesName())
                    .addDatasets("studentNumber", n.getStudentNumber());
        });
        return BaseResponse.success(model);
    }

    @PostMapping("/score")
    public BaseResponse<?> score(ScoreModel scoreModel){
        CharBarModel model = new CharBarModel();

      statisticsService.scoreList(scoreModel).forEach(n->{
            model.addLabels(n.getClassesName())
                    .addDatasets("avgScore", n.getAvgScore())
                    .addDatasets("maxScore", n.getMaxScore())
                    .addDatasets("minScore", n.getMinScore())
                    ;
        });
        return BaseResponse.success(model);
    }



}
